package com.scsj.supermarket.view.fragment.goodssortmodel;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.scsj.supermarket.R;
import com.scsj.supermarket.adapter.FiltrateAdapter;
import com.scsj.supermarket.bean.FiltrateBean;
import com.scsj.supermarket.bean.FiltrateChildBean;

import java.util.ArrayList;
import java.util.List;

/**
 * 商品分类 筛选页面
 */


public class FilterFragment extends Fragment {
    private LinearLayout address_ll;
    private RecyclerView recycler_view;
    private FiltrateAdapter filtrateAdapter;
    private List<FiltrateBean> mDatas;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_goods_sort_filtrate, null);
        initView(view);
        initListener();
        initData();
        return view;
    }


    private void initView(View view) {
        String departmentName = getArguments().getString("departmentName");
        address_ll = view.findViewById(R.id.address_ll);
        recycler_view = view.findViewById(R.id.recycler_view);
        recycler_view.setLayoutManager(new LinearLayoutManager(getActivity()) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        });
//        recycler_view.setNestedScrollingEnabled(false);

    }

    private void initListener() {
        address_ll.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showNext();
            }
        });

    }

    protected void initData() {
        mDatas = new ArrayList<>();
        mDatas.add(new FiltrateBean("品牌", getData("品牌")));
        mDatas.add(new FiltrateBean("包装", getData("包装")));
        mDatas.add(new FiltrateBean("类型", getData("类型")));
        mDatas.add(new FiltrateBean("香型", getData("香型")));
        mDatas.add(new FiltrateBean("口感", getData("口感")));
        mDatas.add(new FiltrateBean("酸度", getData("酸度")));
        mDatas.add(new FiltrateBean("甜度", getData("甜度")));
        mDatas.add(new FiltrateBean("分类", getData("分类")));
        mDatas.add(new FiltrateBean("特性", getData("特性")));
        mDatas.add(new FiltrateBean("产地", getData("产地")));
        mDatas.add(new FiltrateBean("容量", getData("容量")));
        filtrateAdapter = new FiltrateAdapter(getActivity());
        recycler_view.setAdapter(filtrateAdapter);
        filtrateAdapter.addAllData(mDatas);
    }

    private void showNext() {
        Fragment fragment = new AddressFragment();
        FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.setCustomAnimations(R.anim.filtrate_right_in, R.anim.filtrate_left_out, R.anim.filtrate_left_in, R.anim.filtrate_right_out);
        fragmentTransaction.replace(R.id.drawer_content, fragment);
        fragmentTransaction.addToBackStack(null);
        fragmentTransaction.commitAllowingStateLoss();
    }

    private List<FiltrateChildBean> getData(String str) {

        List<FiltrateChildBean> filtrateChildBeans = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            filtrateChildBeans.add(new FiltrateChildBean(str + i));
        }
        return filtrateChildBeans;
    }
}
